package zmee.pmas.form;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.events.ChangeData;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.form.plugin.AbstractFormPlugin;

/**
 * @Author cb
 * @DateTime 2022/12/4 18:17
 * @Description 专家抽取、编辑插件
 */
public class SelectExpertFormPlugin extends AbstractFormPlugin {

    @Override
    public void propertyChanged(PropertyChangedArgs e) {
        super.propertyChanged(e);
        String key = e.getProperty().getName();
        ChangeData changeData = e.getChangeSet()[0];
        if ("expertcount".equals(key)) {
            Integer newValue = (Integer) changeData.getNewValue();
            if (null != newValue) {
                DynamicObject sourcetype = (DynamicObject) this.getModel().getValue("sourcetype");
                if (null != sourcetype) {
                    String number = sourcetype.getString("number");
                    if ("C010405".equals(number)) {
                        if (newValue < 5 || newValue % 2 == 0) {
                            this.getModel().setValue("expertcount", null);
                            this.getView().showTipNotification("当【采购方式】为”公开招标“时，【随机抽取专家数】的字段只能填写大于等于5的奇数！");
                        }
                    } else {
                        if (newValue < 3 || newValue % 2 == 0) {
                            this.getModel().setValue("expertcount", null);
                            this.getView().showTipNotification("当【采购方式】不是”公开招标“时，【随机抽取专家数】的字段只能填写大于等于3的奇数！");
                        }
                    }
                } else {
                    this.getModel().setValue("expertcount", null);
                    this.getView().showTipNotification("请先选择”采购方式“！");
                }
            }
        }
    }
}